from classfile.class_reader import MethodCodeReader


class Instruction:

    def __init__(self, opcode):
        self.opcode = opcode

    def fetchOperands(self, reader: MethodCodeReader):
        pass

    def execute(self, frame):
        pass


#  NoOperandsInstruction 无操作数指令
class NoOperandInstruction(Instruction):

    def fetchOperands(self, reader: MethodCodeReader):
        pass

    def execute(self, frame):
        pass


# BranchInstruction 分支指令
class BranchInstruction(Instruction):

    def __init__(self, opcode):
        super().__init__(opcode)
        self.offset = 0

    def fetchOperands(self, reader: MethodCodeReader):
        self.offset = int(reader.readUInt16())

    def execute(self, frame):
        pass


class Index8Instruction(Instruction):

    def __init__(self, opcode):
        super().__init__(opcode)
        self.index = 0

    def fetchOperands(self, reader: MethodCodeReader):
        self.index = int(reader.readUInt8())  # 读取索引值

    def execute(self, frame):
        pass


class Index16Instruction(Instruction):

    def __init__(self, opcode):
        super().__init__(opcode)
        self.index = 0

    def fetchOperands(self, reader: MethodCodeReader):
        self.index = int(reader.readUInt16())  # 读取索引值

    def execute(self, frame):
        pass
